/**
 * 
 */
package it.irondev.appturismo.action;

import it.irondev.appturismo.entity.Attractions;
import it.irondev.appturismo.entity.Difficulty;
import it.irondev.appturismo.entity.Language;
import it.irondev.appturismo.entity.Restaurant;
import it.irondev.appturismo.entity.Route;
import it.irondev.appturismo.service.IAttractionService;
import it.irondev.appturismo.service.ICityService;
import it.irondev.appturismo.service.IHikeService;
import it.irondev.appturismo.service.ILanguageService;
import it.irondev.appturismo.service.IRestaurantService;
import it.irondev.appturismo.service.IRouteService;
import it.irondev.appturismo.util.ActionHelper;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

/**
 * @author federicocerruto
 *
 */
@Controller("routeAction")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class RouteAction extends AbstractAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 284028159989440557L;

	@Autowired
	IRouteService routeService;
	
	@Autowired
	ILanguageService serviceLanguage;

	@Autowired
	ICityService serviceCity;
	
	@Autowired
	IHikeService serviceHike;
	
	@Autowired
	IAttractionService serviceAttraction;
	
	@Autowired
	IRestaurantService serviceRestaurant;
	
	private Long idRoute;
	private List<Language> listLanguage;
	private Route entityBean;
	private List<Route> routes;
	private List<Difficulty> listDifficulties;
	private List<Attractions> listAttractions;
	private List<Restaurant> listRestaurants;
	private String serializedRouteStages;
	private String stringaSearchLanguage;
	
	
	
	/* (non-Javadoc)
	 * @see it.irondev.appturismo.action.IBaseAction#list()
	 */
	public String list() {
		listLanguage = serviceLanguage.getAllLanguages();
		setStringaSearchLanguage(ActionHelper.buildStringSearch(listLanguage)); 
		return "listRoutes";
	}

	
	public String listJson() {
		routes = routeService.getAllRoutes();
		return "listRouteJson";
	}

	
	public String listMobile() {
		routes = routeService.getAllRoutes();
		return "listRouteMobile";
	}

	
	
	
	public String nuovo() {
		listLanguage = serviceLanguage.getAllLanguages();
		listDifficulties = serviceHike.getAllDifficulties();
		listRestaurants = serviceRestaurant.getAllRestaurants();
		listAttractions= serviceAttraction.getAllAttractions();
		return "newRoute";	
	}

	public String edit() {
		listLanguage = serviceLanguage.getAllLanguages();
		listDifficulties = serviceHike.getAllDifficulties();
		entityBean = routeService.getRouteById(idRoute.intValue());
		return "editRoute";	
	}

	
	public void delete() {
		if (getOper().equalsIgnoreCase("del")) {
			int idEntity = Integer.parseInt(getId());
			routeService.deleteRoute(idEntity);
		}
	}

	
	public String update() {
		routeService.updateRoute(entityBean);
		return "updateRoute";
	}

	
	public String add() {
		routeService.addRoute(entityBean);
		return "addedRoute";
	}


	public Long getIdRoute() {
		return idRoute;
	}


	public void setIdRoute(Long idRoute) {
		this.idRoute = idRoute;
	}


	public List<Language> getListLanguage() {
		return listLanguage;
	}


	public void setListLanguage(List<Language> listLanguage) {
		this.listLanguage = listLanguage;
	}


	public Route getEntityBean() {
		return entityBean;
	}


	public void setEntityBean(Route entityBean) {
		this.entityBean = entityBean;
	}


	public List<Route> getRoutes() {
		return routes;
	}


	public void setRoutes(List<Route> routes) {
		this.routes = routes;
	}


	public String getStringaSearchLanguage() {
		return stringaSearchLanguage;
	}


	public void setStringaSearchLanguage(String stringaSearchLanguage) {
		this.stringaSearchLanguage = stringaSearchLanguage;
	}


	public List<Difficulty> getListDifficulties() {
		return listDifficulties;
	}


	public void setListDifficulties(List<Difficulty> listDifficulties) {
		this.listDifficulties = listDifficulties;
	}


	public List<Attractions> getListAttractions() {
		return listAttractions;
	}


	public void setListAttractions(List<Attractions> listAttractions) {
		this.listAttractions = listAttractions;
	}


	public List<Restaurant> getListRestaurants() {
		return listRestaurants;
	}


	public void setListRestaurants(List<Restaurant> listRestaurants) {
		this.listRestaurants = listRestaurants;
	}


	public String getSerializedRouteStages() {
		return serializedRouteStages;
	}


	public void setSerializedRouteStages(String serializedRouteStages) {
		this.serializedRouteStages = serializedRouteStages;
	}

}
